
package poker.plans.croupier;

import java.util.List;

import jadex.adapter.fipa.*;
import jadex.runtime.IMessageEvent;
import jadex.runtime.Plan;

import poker.beliefs.RequestJoin;
import poker.beliefs.Table;

/**
 *  Plan to handle a join request of a player.
 */

public class RegisterPlayerPlan extends Plan {

    public void body() {
    	// Get join request
    	IMessageEvent request = (IMessageEvent)getInitialEvent();
        // Get the name of the player
        AgentIdentifier aId = (AgentIdentifier)request.getParameter("sender").getValue();
        System.out.println("CROUPIER - New player: " + aId.getName());
        
        // Add the player to the table
        Table t = (Table)getBeliefbase().getBelief("table").getFact();
        t.addPlayer(aId);

        // Set FIPA-performative for the message sent back to the player
    	IMessageEvent msg = request.createReply("inform_action_done");
        sendMessage(msg);
        
        //Update beliefs
        getBeliefbase().getBelief("table").setFact(t);
    }
	
}
